﻿using MediatR;
using Newtonsoft.Json;
using Warehouse.Domain.DTO;
using Warehouse.Infrstructre.Interface;
using Warehouse.Read.API.Applcation.Command.ChartWarehouseCommand;
using static WMSpublic.ParseAPI;
using WMSpublic;

namespace Warehouse.Read.API.Applcation.CommandHandlers.ChartWarehouseCommandHandler
{
    public class ChartOutboundCommandHandler : IRequestHandler<ChartOutboundCommand, List<ChartDto>>
    {

        //出库
        IOutProductRepository opRep;

        public ChartOutboundCommandHandler(IOutProductRepository opRep)
        {
            this.opRep = opRep;
        }


        public async Task<List<ChartDto>> Handle(ChartOutboundCommand request, CancellationToken cancellationToken)
        {
            //出库
            var list = (from op in await opRep.GetAllAsyns()
                         group op by op.AddTime into grouped
                         select new ChartDto
                         {
                             AddTime2 = grouped.Key,
                             TotalPrice2 = grouped.Sum(sp => sp.OutPrice * sp.OutProuductNum)
                         }).ToList();
            return list;
        }

        
    }
}
